import wechatConfig from '../../../../api/config/channel/wechat-config'
import * as globalTypes from '../../../../mutation-types'

/**
 * 查询微信授权列表
 * @param data
 */
export const queryWeChatAuthorizationList = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.queryWeChatAuthorizationList(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询微信对接列表
 * @param data
 */
export const queryWeChatDockList = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.queryWeChatDockList(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 查询微信公众平台对接列表
 * @param data
 */
export const getWxDevModeConfigs = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getWxDevModeConfigs(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 新增 微信对接信息
 * @param data
 */
export const SaveWeChatDock = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.SaveWeChatDock(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 编辑 微信对接信息
 * @param data
 */
export const EditWeChatDock = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.EditWeChatDock(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询微信对接信息
 * @param data
 */
export const GetWeChatDock = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.GetWeChatDock(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除微信对接信息
 * @param data
 */
export const DeleteWeChatDock = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.DeleteWeChatDock(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除微信公众平台对接信息
 * @param data
 */
export const removeWxDevModeConfig = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.removeWxDevModeConfig(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 添加微信公众平台对接信息
 * @param data
 */
export const saveWxDevModeConfig = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.saveWxDevModeConfig(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 获取微信公众平台对接服务IP
 * @param data
 */
export const getWechatAddress = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getWechatAddress(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新微信公众平台对接信息
 * @param data
 */
export const updateWxDevModeConfig = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.updateWxDevModeConfig(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除微信授权信息
 * @param data
 */
export const DeleteWeChatAuth = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.DeleteWeChatAuth(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 保存微信授权信息
 * @param data
 */
export const UpdateWeChatAuth = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.updateWeChatAuth(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 保存微信图片素材
 * @param data
 */
export const saveWeixinMaterial = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.saveWeixinMaterial(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询微信素材
 * @param data
 */
export const getMaterial = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getMaterial(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const getArticle = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getArticle(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 保存微信图文信息
 * @param data
 */
export const saveNewsMaterial = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.saveNewsMaterial(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 保存微信菜单
 * @param data
 */
export const createWeixinMenu = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.createWeixinMenu(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 获取微信菜单
 * @param data
 */
export const getWeixinMenu = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getWeixinMenu(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
* 获取微信小程序列表
* @param data
*/
export const getWeixinMiniAppCheckFileList = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getWeixinMiniAppCheckFileList(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 添加微信小程序
 * @param data
 */
export const addWeixinMiniAppCheckFile = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.addWeixinMiniAppCheckFile(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查看微信小程序
 * @param data
 */
export const getWeixinMiniAppCheckFile = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getWeixinMiniAppCheckFile(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除微信小程序
 * @param data
 */
export const delWeixinMiniAppCheckFile = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.delWeixinMiniAppCheckFile(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除微信小程序
 * @param data
 */
export const updateWeixinMiniAppCheckFile = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.updateWeixinMiniAppCheckFile(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询外引链接列表
 * @param data
 */
export const queryLinkUrlCfg = ({ commit, state, rootState, dispatch }, data) => {
  return wechatConfig.queryLinkUrlCfg(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const queryEcommerceLinkUrlCfg = ({ commit, state, rootState, dispatch }, data) => {
  return wechatConfig.queryEcommerceLinkUrlCfg(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 添加外引链接
 * @param data
 */
export const addLinkUrlCfg = ({ commit, state, rootState, dispatch }, data) => {
  return wechatConfig.addLinkUrlCfg(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const addEcommerceLinkUrlCfg = ({ commit, state, rootState, dispatch }, data) => {
  return wechatConfig.addEcommerceLinkUrlCfg(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const updateEcommerceLinkUrlCfg = ({ commit, state, rootState, dispatch }, data) => {
  return wechatConfig.updateEcommerceLinkUrlCfg(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const delEcommerceLinkUrlCfg = ({ commit, state, rootState, dispatch }, data) => {
  return wechatConfig.delEcommerceLinkUrlCfg(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新外引链接
 * @param data
 */
export const updateLinkUrlCfg = ({ commit, state, rootState, dispatch }, data) => {
  return wechatConfig.updateLinkUrlCfg(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除外引链接
 * @param data
 */
export const delLinkUrlCfg = ({ commit, state, rootState, dispatch }, data) => {
  return wechatConfig.delLinkUrlCfg(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 查询微信小程序配置列表
 * @param data
 */
export const queryWxMiniConfigArr = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.queryWxMiniConfigArr(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 保存微信小程序配置
 * @param data
 */
export const saveWeixinMiniConfig = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.saveWeixinMiniConfig(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 根据id查询微信小程序配置
 * @param data
 */
export const queryWeixinConfigById = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.queryWeixinConfigById(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 更新微信小程序配置
 * @param data
 */
export const updateWeixinMiniConfigById = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.updateWeixinMiniConfigById(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新微信小程序授权配置
 * @param data
 */
export const updateWeixinMiniAuthConfig = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.updateWeixinMiniAuthConfig(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新微信小程序授权列表
 * @param data
 */
export const getWeixinMiniAuthConfigList = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getWeixinMiniAuthConfigList(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除微信小程序授权列表
 * @param data
 */
export const delWeixinMiniAuthConfig = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.delWeixinMiniAuthConfig(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询微信小程序授权详情
 * @param data
 */
export const getWeixinMiniAuthConfigById = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getWeixinMiniAuthConfigById(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除微信小程序配置
 * @param data
 */
export const deleteWxMiniConfig = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.deleteWxMiniConfig(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 添加支付宝小程序
 * @param data
 */
export const addAlipayMini = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.addAlipayMini(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 获取支付宝小程序列表
 * @param data
 */
export const getAlipayMiniList = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getAlipayMiniList(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 修改支付宝小程序
 * @param data
 */
export const editAlipayMini = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.editAlipayMini(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 根据id查支付宝小程序详情
 * @param data
 */
export const getAlipayMiniById = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.getAlipayMiniById(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 根据id删除支付宝小程序
 * @param data
 */
export const delAlipayMiniById = ({commit, state, rootState, dispatch}, data) => {
  return wechatConfig.delAlipayMiniById(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

export const saveWxEnterpriseConfig = ({commit}, data) => {
  return wechatConfig.saveWxEnterpriseConfig(data).then(res => {
    if (res && res.success) {
      return res
    }
  })
}
export const getWxEnterpriseConfigs = ({commit}, data) => {
  return wechatConfig.getWxEnterpriseConfigs(data).then(res => {
    if (res && res.success) {
      return res
    }
  })
}
export const updateWxEnterpriseConfig = ({commit}, data) => {
  return wechatConfig.updateWxEnterpriseConfig(data).then(res => {
    if (res && res.success) {
      return res
    }
  })
}
export const removeWxEnterpriseConfig = ({commit}, data) => {
  return wechatConfig.removeWxEnterpriseConfig(data).then(res => {
    if (res && res.success) {
      return res
    }
  })
}
export const getWxEnterpriseAuthUrl = ({commit}, data) => {
  return wechatConfig.getWxEnterpriseAuthUrl(data).then(res => {
    if (res && res.success) {
      return res
    }
  })
}
export const getWxEnterpriseById = ({commit}, data) => {
  return wechatConfig.getWxEnterpriseById(data).then(res => {
    if (res && res.success) {
      return res
    }
  })
}
